#include "mmpf_i2cm.h"
#include "motor_ctl.h"
#include "hdm_ctl.h"
#include "mmpf_dram.h"

#if SUPPORT_AUTO_FOCUS

#define MOTOR_CTL_ON			ON


#define MOTOR_I2C_ADDR_DW9714   0x0C
#define MOTOR_I2C_ADDR_DRV201   0x0E

#if (CUSTOMER == LON) || ((CUSTOMER == LGT)&&(MODEL == 3)) || (CUSTOMER == ASU)
#define MOTOR_I2C_ADDR          MOTOR_I2C_ADDR_DW9714
#endif
#if ((CUSTOMER == ASU)&&(MODEL < 2))
#undef MOTOR_I2C_ADDR
#endif
#if ((CUSTOMER == CCN)&&(MODEL == 2)) || ((CUSTOMER == ASU)&&(MODEL < 2))
#define MOTOR_I2C_ADDR          MOTOR_I2C_ADDR_DRV201
#endif

MMPF_I2CM_ATTRIBUTE m_motor_I2cmAttribute = {
            SENSOR_I2CM_ID, MOTOR_I2C_ADDR, 8, 8, 0, MMP_FALSE, MMP_FALSE, MMP_FALSE,
            MMP_FALSE, 0, 0, 0, MMPF_I2CM_SPEED_HW_250K, NULL, NULL};  

extern volatile MMP_UBYTE   gbDramID;

MMP_ERR  MMPF_MOTOR_WriteI2C(MMP_USHORT usAddr, MMP_USHORT usData)
{
	if((gbDramID == MMPF_DRAMID_WINBOND_SDR16) || (gbDramID == MMPF_DRAMID_WINBOND_SDR16_1_8V)){
        m_motor_I2cmAttribute.uI2cmID = MMPF_I2CM_ID_0;  // for AIT8433 70 pin package
    }
    else{
        m_motor_I2cmAttribute.uI2cmID = MMPF_I2CM_ID_1;  // for AIT8451 105 pin package
    }
	MMPF_I2cm_WriteReg(&m_motor_I2cmAttribute, usAddr, usData);
	return  MMP_ERR_NONE;
}

MMP_ERR  MMPF_MOTOR_ReadI2C(MMP_USHORT usAddr, MMP_USHORT *usData)
{
	*usData = 0xFF;
	if((gbDramID == MMPF_DRAMID_WINBOND_SDR16) || (gbDramID == MMPF_DRAMID_WINBOND_SDR16_1_8V)){
        m_motor_I2cmAttribute.uI2cmID = MMPF_I2CM_ID_0;  // for AIT8433 70 pin package
    }
    else{
        m_motor_I2cmAttribute.uI2cmID = MMPF_I2CM_ID_1;  // for AIT8451 105 pin package
    }
    MMPF_I2cm_ReadReg(&m_motor_I2cmAttribute, usAddr, usData);
	
	return  MMP_ERR_NONE;
}

#endif

